<table id="sso_website_datagrid" ></table>
<script type="text/javascript">

$(function(){
	
	$('#sso_website_datagrid').datagrid({
		iconCls:'icon-save',
		width:'auto',
		height:'auto',
		nowrap: true,
		fit:true,
		fitColumns:true,
		striped: true,
		url:'${request.contextPath}${namespace?default('')}/mp/sso/website-datagrid.json?ajax=true',
		sortName: 'name',
		sortOrder: 'desc',
		remoteSort: true,
		singleSelect : true,
		idField:'id',
		onBeforeLoad:function(){$('#sso_website_datagrid').datagrid('unselectAll');},
		columns:[[
					{field:'name',title:'${action.getDatagridTitle('name')}',width:50,align:'center'},
					{field:'domain',title:'${action.getDatagridTitle('domain')}',width:80,align:'center'},
					{field:'encode',title:'${action.getDatagridTitle('encode')}',width:80,align:'center'},
					{field:'state',title:'${action.getDatagridTitle('state')}',width:80,align:'center'},
					{field:'publicKey',title:'${action.getDatagridTitle('publicKey')}',width:80,align:'center'},
					{field:'privateKey',title:'${action.getDatagridTitle('privateKey')}',width:80,align:'center'},
					{field:'logoutUrl',title:'${action.getDatagridTitle('logoutUrl')}',width:80,align:'center'},
					{field:'loginUrl',title:'${action.getDatagridTitle('loginUrl')}',width:80,align:'center'},
					{field:'regFlag',title:'${action.getDatagridTitle('regFlag')}',width:80,align:'center'},
					{field:'editpassFlag',title:'${action.getDatagridTitle('editpassFlag')}',width:80,align:'center'},
					{field:'currencyFlag',title:'${action.getDatagridTitle('currencyFlag')}',width:80,align:'center'},
					{field:'extraFlag',title:'${action.getDatagridTitle('extraFlag')}',width:80,align:'center'},
					{field:'caozuo',title:'${action.getProperty('net.esj.background.message','bg.datagrid.action')}',width:80,align:'center',formatter:function(val, rec){
						return '<a href="javascript:;;" onclick="sso_website_edit(\''+rec.id+'\')" >${action.getProperty('net.esj.background.message','bg.datagrid.modify')}</a>&nbsp;|&nbsp;<a href="javascript:;;" onclick="sso_website_delete(\''+rec.id+'\')" >${action.getProperty('net.esj.background.message','bg.datagrid.delete')}</a>';
					}}
				]],
		pagination:true,
		rownumbers:true,
		toolbar:[{
			id:'btnadd',
			text:'${action.getProperty('net.esj.background.message','bg.datagrid.add')}',
			iconCls:'icon-add',
			handler:function(){
				$('<div/>').dialog({
					href:'${request.contextPath}${namespace?default('')}/mp/sso/website-form.htm?ajax=true',
					width:500,   
					height:500,   
					title: '${action.getText('form.add.title')}',
					modal:true,
					maximizable:false,
					collapsible:false,
					minimizable:false,
					resizable:false,
					buttons:[{iconCls : 'icon-ok',
								text:'${action.getProperty('net.esj.background.message','bg.datagrid.save')}',
								handler:function(){
									var d = $(this).closest('.window-body');
									$('#sso_website_form').form('submit', {
										url : '${request.contextPath}${namespace?default('')}/mp/sso/website-add.json',
										onSubmit: function(){
											return $(this).form('validate');
				        				},
										success : function(json) {
											eval("json="+json);
											$.messager.alert(json.title,json.msg,json.level);
											d.dialog('destroy');
											$("#sso_website_datagrid").datagrid('reload');
										}
									});
								}},
								{iconCls : 'icon-undo',
								text:'${action.getProperty('net.esj.background.message','bg.datagrid.reset')}',
								handler:function(){
									$('#sso_website_form').form('clear');
								}}],
					onClose : function() {
						$(this).dialog('destroy');
					}
				});
			}
		}]
	});

});

function sso_website_edit(id){

	$('<div>').dialog({
		href : '${request.contextPath}${namespace?default('')}/mp/sso/website-form.htm?ajax=true',
		width:500,   
		height:500,   
		modal : true,
		title : '${action.getText('form.edit.title')}',
		buttons : [ {
			text : '${action.getProperty('net.esj.background.message','bg.datagrid.edit')}',
			iconCls : 'icon-edit',
			handler : function() {
				var d = $(this).closest('.window-body');
				$('#sso_website_form').form('submit', {
					url : '${request.contextPath}${namespace?default('')}/mp/sso/website-update.json',
					onSubmit: function(){
						return $(this).form('validate');
    				},
					success : function(json) {
						eval("json="+json);
						$.messager.alert(json.title,json.msg,json.level);
						d.dialog('destroy');
						$("#sso_website_datagrid").datagrid('reload');
					}
				});
			}
		} ],
		onClose : function() {
			$(this).dialog('destroy');
		},
		onLoad : function() {
			$.get('${request.contextPath}${namespace?default('')}/mp/sso/website-load.json?id='+id+'&n='+Math.random(),{},function(json){
				$('#sso_website_form').form('load', json);
			},'json');
		}
	});
	
}


function sso_website_delete(id){
	$.messager.confirm('${action.getText('bg.message.info')}', '${action.getText('definition.delete.alert')}', function(b) {
		if (b) {
			$.ajax({
				url : '${request.contextPath}${namespace?default('')}/mp/sso/website-delete.json',
				data:{deletes : id},
				dataType : 'JSON',
				success : function(json) {
					$.messager.alert(json.title,json.msg,json.level);
					$("#sso_website_datagrid").datagrid('reload');
					$('#sso_website_datagrid').datagrid('clearSelections');
				}
			});
		}
	});
}

</script>